package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisNotice;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.AnalysisNoticeDTO;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:06:20
 */
public class AnalysisNoticeConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisNoticeConverts.class);

    public static List<AnalysisNoticeDTO> convert(List<AnalysisNotice> analysisNoticeList) {
        if (CollectionUtils.isEmpty(analysisNoticeList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisNoticeDTO> analysisNoticeListResult = Lists.newArrayList();
        for (AnalysisNotice analysisNotice : analysisNoticeList) {
            analysisNoticeListResult.add(convert(analysisNotice));
        }
        return analysisNoticeListResult;
    }

    public static AnalysisNoticeDTO convert(AnalysisNotice analysisNotice) {
        try {
            return BeanUtils.copy(analysisNotice, AnalysisNoticeDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisNotice到AnalysisNoticeDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisNotice到AnalysisNoticeDTO转换失败", e);
        }
    }

    public static AnalysisNotice convert(AnalysisNoticeDTO analysisNoticeDTO) {
        try {
            return BeanUtils.copy(analysisNoticeDTO, AnalysisNotice.class);
        } catch (Exception e) {
            LOG.error("AnalysisNoticeDTO到AnalysisNotice转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisNoticeDTO到AnalysisNotice转换失败", e);
        }
    }
}